// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <stdio.h>
#include <cstdlib>
#include <kfor/for.h>
#include <cstring>
#include <limits>
#include <iostream>
#include <kfor/array_base.h>

namespace kfor {

    class Array : public ArrayBase {
    private:
        uint32_t inline unsorted_append_size_required(uint32_t value, uint32_t new_length) {
            uint32_t m = std::min(min, value);
            uint32_t M = std::max(max, value);
            uint32_t bnew = required_bits(M - m);
            return METADATA_OVERHEAD + 4 + for_compressed_size_bits(new_length, bnew);
        }

    public:
        void load(const uint32_t *SortedArray, uint32_t array_length, uint32_t m, uint32_t M);

        uint32_t at(uint32_t index);

        bool contains(uint32_t value);

        uint32_t indexOf(uint32_t value);

        bool append(uint32_t value);

        bool insert(size_t index, const uint32_t *values, size_t num_values);

        void remove_index(uint32_t start_index, uint32_t end_index);
    };
} // namespace kfor